package client;

import android.util.Log;

import org.json.JSONException;
import org.json.JSONObject;

import java.io.UnsupportedEncodingException;

import utils.HttpTools;

/**
 * Created by Administrator on 15-10-20.
 */
public final class ClientAPI {
    //单独提取服务器地址部分，避免以后修改麻烦http://mobile.ximalaya.com
    public static final String API_POINT="http://mobile.ximalaya.com";
    private ClientAPI(){}
    //--------------------------------------------------------
    //接口12

    /**
     * API 	/mobile/discovery/v1/categories?device=android&picVersion=10&scale=2
     * @return JsonObject
     */
    public static JSONObject getDiscoverCategories(){
        JSONObject ret=null;
        byte []data=HttpTools.doGet(API_POINT+"/mobile/discovery/v1/categories?device=android&picVersion=10&scale=2");
        if(data!=null)
        {
            try {
                String str=new String(data,"utf-8");
                ret= new JSONObject(str);
            } catch (UnsupportedEncodingException e) {
                e.printStackTrace();
            } catch (JSONException e) {
                e.printStackTrace();
            }
        }
        return ret;
    }

    //--------------------------------------------------------
    //接口11

    /**
     * 获取发现部分，
     * 请求网址：mobile/discovery/v1/recommends?channel=and-f6&device=a
     * ndroid&includeActivity=true&includeSpecial=true&scale=2&version=4.1.7.1
     * @param channel 软件发布渠道
     * @param includeActivity 是否包含活动
     * @param includeSpecial 是否包含精品听单
     * @return
     */
    public static JSONObject getDiscoverRecommed(String channel,
           boolean includeActivity,boolean includeSpecial){
        JSONObject ret=null;
        if(channel==null) {
            channel="and-f6";
        }

        String url = API_POINT + "/mobile/discovery/v1/recommends?" +
                "channel=" + channel +
                "&device=android&" +
                "includeActivity=" +includeActivity+
                "&includeSpecial=" +includeSpecial+
                "&scale=2&version=4.1.7.1";
        Log.d("Task",url);
        byte []data=HttpTools.doGet(url);

        if(data!=null)
        {

            try {
                Log.d("Task",data+"data");
                String str = new String(data,"utf-8");
                Log.d("Task",str);
                ret=new JSONObject(str);

            }  catch (JSONException e) {
                e.printStackTrace();
            } catch (UnsupportedEncodingException e) {
                e.printStackTrace();
            }
        }

        return ret;
    }

    //--------------------------------------------------------
}
